package com.nbsaas.boot.controller.product;

import com.nbsaas.boot.product.ext.apis.ProductExtApi;
import com.nbsaas.boot.product.ext.domain.request.ProductExtRequest;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import com.nbsaas.boot.product.api.domain.request.ProductRequest;
import com.nbsaas.boot.product.api.domain.request.ProductSearch;
import com.nbsaas.boot.product.api.domain.response.ProductResponse;
import com.nbsaas.boot.product.api.domain.simple.ProductSimple;
import com.nbsaas.boot.product.api.apis.ProductApi;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestBody;
import jakarta.annotation.Resource;

/**
*  商品控制器
*/
@RequiresAuthentication
@RestController
@RequestMapping("/product")
public class ProductController {


    @Resource
    private ProductApi productApi;



    @Resource
    private ProductExtApi productExtApi;

    @CreateData
    @RequiresPermissions("product:create")
    @PostMapping("/create")
    public ResponseObject<?> create(@RequestBody ProductExtRequest request) {
        return productExtApi.createExt(request);
    }

    /**
    * 搜索数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("product:search")
    @PostMapping("/search")
    public PageResponse <ProductSimple> search(@RequestBody ProductSearch request) {
        return productApi.search(request);
    }

    /**
    * 列表数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("product:list")
    @PostMapping("/list")
    public ListResponse<ProductSimple> list(@RequestBody ProductSearch request) {
        return productApi.list(request);
    }


   /**
   * 修改数据
   * @param request
   * @return
   */
   @RequiresPermissions("product:update")
   @UpdateData
   @PostMapping("/update")
   public ResponseObject<?> update(@RequestBody @Validated(UpdateOperator.class) ProductExtRequest request) {
       return productExtApi.updateExt(request);
   }

    /**
    * 删除数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("product:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) ProductRequest request) {
        return productApi.delete(request);
    }

    /**
    * 查看数据
    *
    * @param request
    * @return
    */
    @SearchData
    @RequiresPermissions("product:view")
    @PostMapping("/view")
    public ResponseObject <ProductResponse> view(@RequestBody @Validated(ViewOperator.class) ProductRequest  request) {
        return productApi.view(request);
    }
}